package com.wgts.wgts.mvp.view.activity.wgtsteam;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.base.BaseActivity;
import com.wgts.wgts.dagger.ComponentHolder;
import com.wgts.wgts.dagger.component.DaggerWgtsMyTeamActivityComponent;
import com.wgts.wgts.dagger.module.WgtsMyTeamActivityModule;
import com.wgts.wgts.mvp.presenter.IWgtsMyTeamActivityPresenter;
import com.wgts.wgts.mvp.view.IWgtsMyTeamActivityView;
import com.wgts.wgts.netmodle.resp.WgtsFansCountEntity;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WgtsMyTeamActivity extends BaseActivity implements IWgtsMyTeamActivityView {
    @BindView(R.id.back_btn_image)
    ImageView backBtnImage;
    @BindView(R.id.back_btn_ly)
    LinearLayout backBtnLy;
    @BindView(R.id.include_title)
    TextView includeTitle;
    @BindView(R.id.include_text)
    TextView includeText;
    @BindView(R.id.include_right_image)
    ImageView includeRightImage;
    @BindView(R.id.include_right_ly)
    LinearLayout includeRightLy;
    @BindView(R.id.img_one)
    ImageView imgOne;
    @BindView(R.id.tv_one_title)
    TextView tvOneTitle;
    @BindView(R.id.img_one_arrow)
    ImageView imgOneArrow;
    @BindView(R.id.linear_one)
    LinearLayout linearOne;
    @BindView(R.id.img_two)
    ImageView imgTwo;
    @BindView(R.id.tv_two_title)
    TextView tvTwoTitle;
    @BindView(R.id.img_two_arrow)
    ImageView imgTwoArrow;
    @BindView(R.id.linear_two)
    LinearLayout linearTwo;

    @Inject
    IWgtsMyTeamActivityPresenter presenter;
    @BindView(R.id.tv_one_number)
    TextView tvOneNumber;
    @BindView(R.id.tv_two_number)
    TextView tvTwoNumber;


    @Override
    public void init() {
        DaggerWgtsMyTeamActivityComponent
                .builder()
                .appComponent(ComponentHolder.getInstance().getAppComponent())
                .wgtsMyTeamActivityModule(new WgtsMyTeamActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_term);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        includeTitle.setText("我的团队");
        presenter.wgtsFansCount();
    }

    @OnClick({R.id.back_btn_ly, R.id.linear_one, R.id.linear_two})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn_ly:
                finish();
                break;
            case R.id.linear_one:
                jump(WgtsMyFansActivity.class, "一级粉丝", "0");
                break;
            case R.id.linear_two:
                jump(WgtsMyFansActivity.class, "二级粉丝", "1");
                break;
        }
    }

    private void jump(Class activity, String title, String relationLevel){
        Intent intent = new Intent(this, activity);
        intent.putExtra(WgtsMyFansActivity.TITLE, title);
        intent.putExtra(WgtsMyFansActivity.RELATIONLEVEL, relationLevel);
        startActivity(intent);
    }

    @Override
    public void onError(int status, String msg) {

    }


    @Override
    public void fansCount(List<WgtsFansCountEntity> wgtsFansCountEntitys) {
        for (WgtsFansCountEntity item : wgtsFansCountEntitys) {
            if (item.relationLevel == 0) {
                tvOneNumber.setText(String.valueOf(item.count) + "人");
            }
            if(item.relationLevel == 1){
                tvTwoNumber.setText(String.valueOf(item.count) + "人");
            }
        }
    }
}
